package com.larry.tinyweb.core;

import com.larry.tinyweb.core.annotation.AnnotationContainer;
import com.larry.tinyweb.core.annotation.Unit;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by larry on 16/12/4.
 *
 * 调用实体
 */
public class InvokeEntity implements ActionInvoke {
    private String requestKey;
    private Object action;
    private Method method;
    private Unit unit;

    public InvokeEntity(String requestKey, Object action, Unit unit, Method method) {
        this.requestKey = requestKey;
        this.action = action;
        this.method = method;
        this.unit = unit;
    }

    public InvokeEntity(String requestKey, Unit unit, Method method) {
        this.requestKey = requestKey;
        this.method = method;
        this.unit = unit;
    }

    @Override
    public void invoke(RequestEntity requestEntity) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {
        method.invoke(AnnotationContainer.getContainer().getFromContainer(unit), requestEntity);
    }
}
